package com.project.lk.nurseapp.base;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;


import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.utils.AppManager;

import butterknife.ButterKnife;
import butterknife.Unbinder;
/**
 * 功能介绍：BaseActivity的创建，用来给Activity用来继承用
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public abstract class BaseActivity extends AppCompatActivity {


    private Unbinder mBind;
//    private SocketService.WsBinder mBinder;
    private Intent service;
    private String wsUrl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(getLayoutId());
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(getResources().getColor(R.color.applyTextColor));
                //底部导航栏
                //window.setNavigationBarColor(activity.getResources().getColor(colorResId));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
//设置全屏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);
//       getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
     AppManager.getAppManager().addActivity(this);
        //绑定黄油刀
        mBind = ButterKnife.bind(this);

        initBefore(savedInstanceState);
        init();

    }


    public void setUrl(String url){
        this.wsUrl=url;
    }


    public void initBefore(Bundle savedInstanceState) {

    }

    @Override
    public void onBackPressed() {
        AppManager.getAppManager().finishActivity();
    }



    protected void init() {
        initData();
        initView();
      //  Toast.makeText(this, "" + NIMClient.getStatus(), Toast.LENGTH_LONG).show();
        //放到所有UI的基类里面注册，所有的UI实现onKickOut接口
    }
    protected abstract void initData();
    protected abstract void initView();

    protected abstract int getLayoutId();

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mBind!=null){
            mBind.unbind();
            //内存泄漏检测工具
//            RefWatcher refWatcher = BaseApp.getRefWatcher(this);
//            refWatcher.watch(this);
        }
    }

}
